package com.elegantsoft.pakistannews;

import java.util.ArrayList;
import java.util.Arrays;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.atiffarrukh.pakistannews.R;
import com.google.analytics.tracking.android.EasyTracker;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends SherlockActivity {
	private boolean english;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		Bundle b = getIntent().getExtras();
		english = b.getBoolean("english");
		Log.d("English Selected", "" + english);
		ListView lv = (ListView) findViewById(R.id.catList);
		MyCustommAdapter adapter;
		if (english) {
			String[] categories = { "Headlines", "Pakistan", "World",
					"Buisness", "Sports", "Entertainment", "Health", "Science",
					"Technology" };
			ArrayList<String> categoriesList = new ArrayList<String>();
			categoriesList.addAll(Arrays.asList(categories));

			adapter = new MyCustommAdapter(this, categories);
			lv.setAdapter(adapter);
		} else {
			String[] categories = { "Headlines", "Pakistan", "World",
					"Buisness", "Sports" };
			ArrayList<String> categoriesList = new ArrayList<String>();
			categoriesList.addAll(Arrays.asList(categories));

			adapter = new MyCustommAdapter(this, categories);
			lv.setAdapter(adapter);
		}

		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				TextView tv = (TextView) view.findViewById(R.id.text1);
				String cat = tv.getText().toString();
				Intent i = new Intent(getApplicationContext(),
						com.elegantsoft.pakistannews.Channel.class);
				i.putExtra("category", cat);
				i.putExtra("english", english);
				startActivity(i);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getSupportMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.action_settings:
			Intent i = new Intent(getApplicationContext(), Preferences.class);
			startActivity(i);
			break;
		case android.R.id.home:
			// Do whatever you want, e.g. finish()
			Intent in = new Intent(getApplicationContext(),
					EnglishUrduChoice.class);
			in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			// i.putExtra("category",English );
			startActivity(in);
			finish();
			return true;
		default:
			break;
		}
		return true;
	}
	 @Override
	  public void onStart() {
	    super.onStart();
	  
	   // EasyTracker.getInstance().activityStart(this); // Google Analytics.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    
	    //EasyTracker.getInstance().activityStop(this); // Google Analytics.
	  }

}
